//
//  CustomView.m
//  UI05_homeWork
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomView.h"

@implementation CustomView

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    
    if (self) {

        [self createViews];
    }
    return self;
    
}

-(void)createViews {
    
    NSMutableArray *color = [NSMutableArray arrayWithObjects:[UIColor blueColor], [UIColor redColor], [UIColor greenColor], [UIColor yellowColor], [UIColor grayColor], nil];
    
    for (int i = 0; i < 5; i++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * 20, i * 20, 200 - i * 40, 200 - i * 40)];
        view.tag = 100 + i;
        view.backgroundColor = color[i];
        [self addSubview:view];
        [view release];
    }
    
//    self.one = [[UIView alloc] initWirethFrame:CGRectMake(0, 0, 200, 200)];
//    self.one.backgroundColor = [UIColor blueColor];
//    [self addSubview:self.one];
//    [self.one release];
//    
//    self.two = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 160, 160)];
//    self.two.backgroundColor = [UIColor redColor];
//    [self addSubview:self.two];
//    [self.two release];
//    
//    self.three = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 120, 120)];
//    self.three.backgroundColor = [UIColor yellowColor];
//    [self addSubview:self.three];
//    [self.three release];
//    
//    self.four = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 80, 80)];
//    self.four.backgroundColor = [UIColor greenColor];
//    [self addSubview:self.four];
//    [self.four release];
//    
//    self.five = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 40, 40)];
//    self.five.backgroundColor = [UIColor grayColor];
//    [self addSubview:self.five];
//    [self.five release];
    
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(changeColor:) userInfo:nil repeats:YES];
    
}

-(void)changeColor:(NSTimer *)timer {
    
//    UIColor *nima = self.one.backgroundColor;
//    self.one.backgroundColor = self.two.backgroundColor;
//    
//    self.two.backgroundColor = self.three.backgroundColor;
//    
//    self.three.backgroundColor = self.four.backgroundColor;
//    
//    self.four.backgroundColor = self.five.backgroundColor;
//    
//    self.five.backgroundColor = nima;
    UIColor *temp = [self viewWithTag:100].backgroundColor;
    for (int i = 0; i < 5; i++) {
        
        [self viewWithTag:100 + i].backgroundColor = [self viewWithTag:101 + i].backgroundColor;
        
    }
    [self viewWithTag:104].backgroundColor = temp;
    
    
}



@end
